package mp

import (
	"duoke/model"
	"duoke/service"
	"duoke/utils/gconv"
	"duoke/utils/request"
	"duoke/utils/response"
	"duoke/utils/valid"
	"github.com/gin-gonic/gin"
	"github.com/go-playground/validator/v10"
)

var CourseVideo = new(courseVideoCtl)

type courseVideoCtl struct{}

func (ctl *courseVideoCtl) List(c *gin.Context) {
	req := request.JsonMap(c)
	id := gconv.Int(req["id"])
	if id == 0 {
		response.Error(c, "参数缺失【id】", nil)
		return
	}
	Type := gconv.Int(req["type"])
	if Type == 0 {
		response.Error(c, "参数缺失【type】", nil)
		return
	}
	info, err := service.CourseVideo.Info(c, id, Type,
		"course_video.id,url,title,type,duration,price,is_points,carmine_id,is_feel,white_list,white_list")
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}

	response.Success(c, "success", info)
}
func (ctl *courseVideoCtl) GivePoints(c *gin.Context) {
	var req model.ReqGivePoints
	if err := c.ShouldBindJSON(&req); err != nil {
		response.Error(c, valid.GetError(err.(validator.ValidationErrors), req), nil)
		return
	}
	err := service.CourseVideo.GivePoints(c, &req)
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "赠送成功", nil)
}
func (ctl *courseVideoCtl) SaveWatch(c *gin.Context) {
	req := request.JsonMap(c)
	id := gconv.Int(req["id"])
	if id == 0 {
		response.Error(c, "参数缺失【id】", nil)
		return
	}
	err := service.CourseProgress.SaveWatch(c, &model.ReqId{Id: id})
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "success", nil)
}
